//
//  NewsCell2.m
//  CarLife
//
//  Created by yu on 2018/1/11.
//  Copyright © 2018年 jpas. All rights reserved.
//

#import "NewsCell2.h"

@interface NewsCell2 ()

@property (nonatomic, strong) NSArray *imageViewsArray;

@end

@implementation NewsCell2

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    _imageViewsArray = @[_imageView0, _imageView1, _imageView2];

    self.contentView.sd_equalWidthSubviews = _imageViewsArray;
    
    CGFloat margin15 = 15; CGFloat margin10 = 10;
    UIView *contentView = self.contentView;
    
    _titleLabel.sd_layout
    .leftSpaceToView(contentView, margin15)
    .topSpaceToView(contentView, margin10)
    .rightSpaceToView(contentView, margin15)
    .autoHeightRatio(0);
    
    _imageView0.sd_layout
    .topSpaceToView(_titleLabel, margin10)
    .leftSpaceToView(contentView, margin15)
    .autoHeightRatio(0.75);
    
    _imageView1.sd_layout
    .topSpaceToView(_titleLabel, margin10)
    .leftSpaceToView(_imageView0, margin15)
    .autoHeightRatio(0.75);
    
    _imageView2.sd_layout
    .topSpaceToView(_titleLabel, margin10)
    .leftSpaceToView(_imageView1, margin15)
    .rightSpaceToView(contentView, margin15)
    .autoHeightRatio(0.75);
    
    _authorLabel.sd_layout
    .topSpaceToView(_imageView0, margin10)
    .leftSpaceToView(contentView, margin15)
    .heightIs(margin15);
    [_authorLabel setSingleLineAutoResizeWithMaxWidth:kScreenWidth/2];
    
    _timeLabel.sd_layout
    .leftSpaceToView(_authorLabel, margin15)
    .centerYEqualToView(_authorLabel)
    .heightIs(margin15);
    
    [self setupAutoHeightWithBottomView:_authorLabel bottomMargin:margin10];
}

- (void)setNewsModel:(NewsModel *)newsModel
{
    _newsModel = newsModel;
    self.titleLabel.text = newsModel.title;
    self.authorLabel.text = NSStringFormat(@"来源：%@",newsModel.author_name);
    self.timeLabel.text = newsModel.date;
    [newsModel.imagesArray enumerateObjectsUsingBlock:^(NSString * _Nonnull str, NSUInteger idx, BOOL * _Nonnull stop) {
        UIImageView *imageView = _imageViewsArray[idx];
        [imageView sd_setImageWithURL:[NSURL URLWithString:str] placeholderImage:IMAGE_NAMED(@"dance")];
    }];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
